home *** CD-ROM | disk | FTP | other *** search
- /* routine to open all files that will be needed for the work...
- */
-
- #include "mergeIndices.z.h"
-
- extern Str255 fn[3][3];
- extern int vRef[3][3], refNum[3][3], x0, y0;
- extern long first_text_file_size;
-
-
- int open_all_files ()
- {
- give_msg ("\pChoose first dataspace to be merged (second will be appended to it)...");
- if (! getTextFile (FIRSTIN))
- return (0);
- give_msg ("\pChoose second dataspace to be merged (follows previous choice)...");
- if (! getTextFile (SECONDIN))
- return (0);
- give_msg ("\pName the merged file -- in same folder as first dataspace, please!");
- if (! putTextFile ())
- return (0);
-
- return (1);
- }
-
-
- /* routine to get a text file name, vRef, and refNum ... first for a brwsr
- * database document file, then for the affiliated key and ptr files.
- * If a .k or .p file isn't found, ask the user for help.... use SFGetFile
- * approach.... flag success with 1, return 0 if failure or user cancel...
- */
-
- int getTextFile (filenum)
- int filenum;
- {
- if (! getFileZ (&fn[filenum][TEXTFILE], &vRef[filenum][TEXTFILE]))
- return (0);
- if (FSOpen (&fn[filenum][TEXTFILE], vRef[filenum][TEXTFILE],
- &refNum[filenum][TEXTFILE]) != noErr)
- {
- give_msg ("\pFatal error opening dataspace text file! Click mouse to exit...");
- beepWait ();
- return (0);
- }
-
- if (filenum == FIRSTIN &&
- GetEOF (refNum[filenum][TEXTFILE], &first_text_file_size)
- != noErr)
- {
- give_msg ("\pFatal error getting text file length! Click mouse to exit...");
- beepWait ();
- return (0);
- }
-
- pStrCopy ((char *)fn[filenum][TEXTFILE], (char *)fn[filenum][KEYFILE]);
- *(fn[filenum][KEYFILE] + *fn[filenum][KEYFILE] + 1) = '.';
- *(fn[filenum][KEYFILE] + *fn[filenum][KEYFILE] + 2) = 'k';
- *fn[filenum][KEYFILE] += 2;
- vRef[filenum][KEYFILE] = vRef[filenum][TEXTFILE];
-
- if (FSOpen (&fn[filenum][KEYFILE], vRef[filenum][KEYFILE],
- &refNum[filenum][KEYFILE]) != noErr)
- {
- give_msg ("\pCan't find dataspace key file -- please locate it...");
- if (! getFileZ (&fn[filenum][KEYFILE], &vRef[filenum][KEYFILE]))
- return (0);
- if (FSOpen (&fn[filenum][KEYFILE], vRef[filenum][KEYFILE],
- &refNum[filenum][KEYFILE]) != noErr)
- {
- give_msg ("\pFatal error opening dataspace key file! Click mouse to exit...");
- beepWait ();
- return (0);
- }
- }
-
- pStrCopy ((char *)fn[filenum][TEXTFILE], (char *)fn[filenum][PTRFILE]);
- *(fn[filenum][PTRFILE] + *fn[filenum][PTRFILE] + 1) = '.';
- *(fn[filenum][PTRFILE] + *fn[filenum][PTRFILE] + 2) = 'p';
- *fn[filenum][PTRFILE] += 2;
- vRef[filenum][PTRFILE] = vRef[filenum][TEXTFILE];
-
- if (FSOpen (&fn[filenum][PTRFILE], vRef[filenum][PTRFILE],
- &refNum[filenum][PTRFILE]) != noErr)
- {
- give_msg ("\pCan't find dataspace ptr file -- please locate it...");
- if (! getFileZ (&fn[filenum][PTRFILE], &vRef[filenum][PTRFILE]))
- return (0);
- if (FSOpen (&fn[filenum][PTRFILE], vRef[filenum][PTRFILE],
- &refNum[filenum][PTRFILE]) != noErr)
- {
- give_msg ("\pFatal error opening dataspace ptr file! Click mouse to exit...");
- beepWait ();
- return (0);
- }
- }
-
- return (1);
- }
-
-
- /* routine to get a name for the merged output text file, using SFPutFile
- * approach ... then open the associated key and ptr files for it ...
- * return 0 if cancel or failure, 1 if success...
- *
- * ... NOTE that the merged text file had better be in the same folder
- * on the same disk as the first input file, so that our quick append
- * method can work -- so warn the user, and refuse to accept a name
- * anyplace else! ... also note that we don't actually create or open
- * the merged text file, since we're going to do a fast append of the
- * second text file to the end of the first one, in place, and then just
- * rename the first file to the merged output name....
- */
-
- int putTextFile ()
- {
- SFTypeList myTypes;
- Point SFPwhere;
- SFReply reply;
- Str255 defaultfn;
-
- SFPwhere.v = 106 + y0;
- SFPwhere.h = 104 + x0;
-
- pStrCopy ("\pMerged Dataspace File", (char *)fn[MERGEDOUT][TEXTFILE]);
-
- tryagain:
- SFPutFile(SFPwhere, "\p", fn[MERGEDOUT][TEXTFILE], 0L, &reply);
- if (!reply.good)
- return (0);
- if (reply.vRefNum != vRef [FIRSTIN][TEXTFILE])
- {
- give_msg ("\pMerged dataspace MUST be in same folder as first one! Try again...");
- SysBeep (10);
- goto tryagain;
- }
-
- pStrCopy((char *)reply.fName, (char *)fn[MERGEDOUT][TEXTFILE]);
- vRef[MERGEDOUT][TEXTFILE] = reply.vRefNum;
-
- pStrCopy ((char *)fn[MERGEDOUT][TEXTFILE],
- (char *)fn[MERGEDOUT][KEYFILE]);
- *(fn[MERGEDOUT][KEYFILE] + *fn[MERGEDOUT][KEYFILE] + 1) = '.';
- *(fn[MERGEDOUT][KEYFILE] + *fn[MERGEDOUT][KEYFILE] + 2) = 'k';
- *fn[MERGEDOUT][KEYFILE] += 2;
- vRef[MERGEDOUT][KEYFILE] = vRef[MERGEDOUT][TEXTFILE];
- if (! CreateFile (&fn[MERGEDOUT][KEYFILE], &vRef[MERGEDOUT][KEYFILE],
- &refNum[MERGEDOUT][KEYFILE]))
- {
- give_msg ("\pFatal error creating merged key file! Click mouse to exit...");
- beepWait ();
- return (0);
- }
-
- pStrCopy ((char *)fn[MERGEDOUT][TEXTFILE],
- (char *)fn[MERGEDOUT][PTRFILE]);
- *(fn[MERGEDOUT][PTRFILE] + *fn[MERGEDOUT][PTRFILE] + 1) = '.';
- *(fn[MERGEDOUT][PTRFILE] + *fn[MERGEDOUT][PTRFILE] + 2) = 'p';
- *fn[MERGEDOUT][PTRFILE] += 2;
- vRef[MERGEDOUT][PTRFILE] = vRef[MERGEDOUT][TEXTFILE];
- if (! CreateFile (&fn[MERGEDOUT][PTRFILE], &vRef[MERGEDOUT][PTRFILE],
- &refNum[MERGEDOUT][PTRFILE]))
- {
- give_msg ("\pFatal error creating merged ptr file! Click mouse to exit...");
- beepWait ();
- return (0);
- }
-
- return (1);
- }
-
-
-
- /* create a file, based on LSC demo prog... give it my ^z filetype...
- */
-
- int CreateFile (fn, vRef, theRef)
- Str255 *fn;
- int *vRef;
- int *theRef;
- {
- int io;
-
- io = Create (fn, *vRef, '????', 'CTLZ');
- if ((io == noErr) || (io == dupFNErr))
- io = FSOpen (fn, *vRef, theRef);
- return ((io == noErr) || (io == dupFNErr));
- }
-
-
-
- /* following variables and routine do the standard files dialog
- * to get the name of the file to use ... cribbed from the MiniEdit
- * example that comes with LSC....
- */
-
- int getFileZ (fnp, vRefp)
- Str255 *fnp;
- int *vRefp;
- {
- SFTypeList myTypes;
- Point SFGwhere;
- SFReply reply;
-
- SFGwhere.v = 90 + y0;
- SFGwhere.h = 82 + x0;
- myTypes[0] = 'TEXT';
- SFGetFile (SFGwhere, "\p", 0L, 1, myTypes, 0L, &reply);
- if (reply.good)
- {
- pStrCopy ((char *)reply.fName, (char *)fnp);
- *vRefp = reply.vRefNum;
- return (1);
- }
- else return (0);
- }
-
-
- /* routine to copy a pascal string from one place to another.... used in
- * above Standard Files routine....
- */
-
- void pStrCopy (p1, p2)
- register char *p1, *p2;
- {
- register int len;
-
- len = *p2++ = *p1++;
- while (--len >= 0)
- *p2++ = *p1++;
- return;
- }
-
-
-
-
-